package com.extweb4j.core.model;

import java.util.ArrayList;
import java.util.List;

import com.extweb4j.core.kit.LoginKit;
/**
 * 消息部门关系
 * @author Administrator
 *
 */
public class ExtMsgUser extends CoreModel<ExtMsgUser>{

	
	private static final long serialVersionUID = 1L;

	public static ExtMsgUser dao = new ExtMsgUser();

	public ExtMsgUser findFirstByMsgId(String msg_id,String uid){
		List<Object> paras = new ArrayList<Object>();
		StringBuffer buffer = new StringBuffer();
		buffer.append(" SELECT * FROM ext_msg_user");
		buffer.append(" WHERE msg_id=?");
		paras.add(msg_id);
		//判断是否超级管理员
		if(!LoginKit.isAdmin(uid)){
			buffer.append(" AND user_id = ? ");
			paras.add(uid);
		}
		return ExtMsgUser.dao.findFirst(buffer.toString(),paras.toArray());
	}

	public List<ExtUser> findUserByMsgId(String msg_id){
		StringBuffer buffer = new StringBuffer();
		buffer.append(" SELECT * FROM ext_user u");
		buffer.append(" LEFT JOIN  ext_msg_user m ON m.user_id = u.id ");
		buffer.append(" WHERE m.msg_id=?");
		return ExtUser.dao.find(buffer.toString(),msg_id);
	}
}
